﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCP.Recruiting.ApplicationServices.ViewModels;
using NCP.Recruiting.Domain.Aggregates.Companies;
using NCP.Recruiting.Domain.Aggregates.Jobpositions;
using NCP.Recruiting.ApplicationServices.Contracts;
using NCP.Recruiting.Domain.Aggregates.Tags;
using NCP.Recruiting.Domain.Aggregates.Resumes;
using NCP.Infrastructure.Common;

namespace NCP.Recruiting.ApplicationServices.ModelConversions
{
    public static class ConversionHelper
    {
        public static CompanyViewModel ConvertToViewModel(this Company entity)
        {
            return new CompanyViewModel
            {
                CompanyName = entity.CompanyName
            };
        }

        public static User ConvertToUserViewModel(this Company entity)
        {
            return new User
            {
                CompanyName = entity.CompanyName,
                Id = entity.Id,
                Username = entity.Username,
                FullName = entity.Contact
            };
        }


        public static IEnumerable<CompanyViewModel> ConvertToViewModels(this IEnumerable<Company> companies)
        {
            List<CompanyViewModel> companyViewModels = new List<CompanyViewModel>();

            foreach (var company in companies)
            {
                companyViewModels.Add(company.ConvertToViewModel());
            }

            return companyViewModels;
        }

        public static TagViewModel ConvertToViewModel(this Tag tag)
        {
            return new TagViewModel
            {
                Id = tag.Id,
                CompanyId = tag.CompanyId,
                Deleted = tag.Deleted,
                TagCount = tag.TagCount,
                TagName = tag.TagName,
                Selected = tag.Selected
            };
        }

        public static IEnumerable<TagViewModel> ConvertToViewModels(this IEnumerable<Tag> tags)
        {
            List<TagViewModel> tagViewModels = new List<TagViewModel>();

            foreach (var tag in tags)
            {
                tagViewModels.Add(
                    tag.ConvertToViewModel()
                    );
            }

            return tagViewModels;
        }

        public static ResumeViewModel ConvertToViewModel(this Resume currentItem)
        {
            var result = currentItem.CopyItem<Resume, ResumeViewModel>();
            result.ResumeId = currentItem.Id;
            result.SetLovName();
            result.CareerGoal = currentItem.CopyItem<Resume, CareerGoalViewModel>();
            result.CareerGoal.SetLovName();
            result.WorkExperiences = currentItem.Works.CopyListTo<Work, WorkExperienceViewModel>();
            result.Trainings = currentItem.Trainings.CopyListTo<Training, TrainingViewModel>();
            result.Skills = currentItem.Skills.CopyListTo<Skill, SkillViewModel>();
            result.Certifications = currentItem.Certifications.CopyListTo<Certification, CertificationViewModel>();
            result.Educations = currentItem.Educations.CopyListTo<Education, EducationViewModel>();
            return result;
        }
    }
}
